package ru.spb.osll.myfit.client.view;


import java.util.List;


import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.google.gwt.user.client.ui.Widget;
import ru.spb.osll.myfit.client.widget.ResizableResultTable;
import ru.spb.osll.myfit.client.widget.filter.*;
import ru.spb.osll.myfit.common.ExecutingResult;
import ru.spb.osll.myfit.common.MetadataColumnDef;


public class TestTableView extends AbstractTestView {

  private static final String DEFAULT_TITLE = "Tests Results";

  private final Label m_titleLabel = new Label(DEFAULT_TITLE);
  private ResizableResultTable m_resultTable;
  private FiltrationWidget m_filtrationWidget;
  private Widget m_rootPanel;

  public TestTableView() {
    m_titleLabel.addStyleName("testResultTextStyle");
    m_titleLabel.setWidth("300px");
    m_rootPanel = createRootPanel();
  }

  @Override
  public Widget getRootWidget() {
    return m_rootPanel;
  }

  @Override
  protected Widget createEditPanel() {
    VerticalPanel editPanel = (VerticalPanel)super.createEditPanel();
    editPanel.add(m_titleLabel);
    return editPanel;
  }

  @Override
  protected Widget createContentPanel() {
    m_resultTable = new ResizableResultTable();

    VerticalPanel mainPanel = new VerticalPanel();
    mainPanel.setWidth("100%");
    mainPanel.setHeight("100%");

    m_filtrationWidget = new FiltrationWidget();
    mainPanel.add(m_filtrationWidget);
    mainPanel.setCellHeight(m_filtrationWidget, "5px");

    mainPanel.add(m_resultTable.getWidget());

    return mainPanel;
  }

  public void createMetadataCol(MetadataColumnDef colDef) {
    m_resultTable.createMetadataCol(colDef);
  }

  public void addResultToWidget(List<ExecutingResult> list) {
    if (list != null) {
      for (ExecutingResult result : list) {
        m_resultTable.addResult(result);
      }
    }
  }

  public void updateResult(ExecutingResult result) {
    m_resultTable.updateResult(result);
  }

  public FiltrationWidget getFiltrationWidget() {
    return m_filtrationWidget;
  }

  public void refresh() {
    m_resultTable.refreshTable();
  }
}
